package com.idrive.database.dao;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;

public class PhoneBookDao {

	private Context context;

	public PhoneBookDao(Context context) {

		this.context = context;

	}

	public Map<String, String> getContacts() {
		Map<String, String> map = new HashMap<String, String>();
		Cursor cursor = context.getContentResolver().query(Contacts.CONTENT_URI,
		        new String[] { Contacts.DISPLAY_NAME }, null, null, null);
		if (cursor != null) {
			while (cursor.moveToNext()) {
				Cursor c = context.getContentResolver().query(Phone.CONTENT_URI,
				        new String[] { Phone.NUMBER, Phone.TYPE },
				        " DISPLAY_NAME = '" + cursor.getString(cursor.getColumnIndex(Contacts.DISPLAY_NAME)) + "'",
				        null, null);
				map.put(c.getString(c.getColumnIndex(Phone.NUMBER)),
				        cursor.getString(cursor.getColumnIndex(Contacts.DISPLAY_NAME)));

			}
		}

		return map;
	}
}
